<!-- 搜索项目 -->
<template>
  <h-select-input-popup
    ref="hSelectInputPopup"
    v-model="val"
    v-bind="$attrs"
    v-on="$listeners"
    :params="queryParams"
    :keywords.sync="keywords"
    :getList="getList"
    @getDetail="getDetail"
    :isMulti="muitFlag"
    searchPlaceholder="请输入单据编号"
    @change="$emit('change', $event)"
  >
    <template v-slot:default="{ item }">
      <view class="project-item">
        <view class="option">
          <view class="lf">单据编号</view>
          <view class="rl">{{ item.billNo }}</view>
        </view>
        <view class="option">
          <view class="lf">申请公司</view>
          <view class="rl">{{ item.applicant_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">报销金额（元）</view>
          <view class="rl">{{ item.reimbursementAmount }}</view>
        </view>
        <view class="option">
          <view class="lf">本次付款金额（元）</view>
          <view class="rl">{{ item.payAmount }}</view>
        </view>
        <view class="option">
          <view class="lf">是否付款</view>
          <view class="rl">{{ item.isPay_dictText }}</view>
        </view>
        <view class="option">
          <view class="lf">报销说明</view>
          <view class="rl">{{ item.applyExplain }}</view>
        </view>
      </view>
    </template>
  </h-select-input-popup>
</template>

<script>
import { erpFinanceReimbursementBill, erpFinanceReimbursementBillQueryById } from '@/api/index.js'

export default {
  name: 'HSelectOilCardInputPopup',
  data() {
    return {
      getList: erpFinanceReimbursementBill,
      params: {
        column: 'createTime',
        order: 'desc',
        pageNo: 1,
        pageSize: 10,
      },
      keywords: '',
    }
  },
  model: {
    prop: 'value',
    event: 'input',
  },
  props: {
    value: {
      type: [String, Number, Array],
      default: null,
    },
    muitFlag: {
      type: Boolean,
      default: false,
    },
    teamId: {
      type: [String, Number],
      default: null,
    },
    applicant: {
      type: [String, Number],
      default: null,
    },
    checkStatus: {
      type: [String, Number],
      default: null,
    },
    isBalanced: {
      type: [String, Number],
      default: 0,
    },
  },
  computed: {
    val: {
      get() {
        return this.value
      },
      set() {
        this.$emit('input', this.value)
      },
    },
    queryParams() {
      const params = {
        ...this.params,
      }
      if (this.keywords) {
        params.billNo = '*' + this.keywords + '*'
      }
      if (this.teamId) {
        params.teamId = this.teamId
      }
      if (this.applicant) {
        params.applicant = this.applicant
      }
      if (this.checkStatus) {
        params.checkStatus = this.checkStatus
      }
      if (this.isBalanced) {
        params.isBalanced = this.isBalanced
      }
      return params
    },
  },
  methods: {
    // 获取详情
    getDetail(value) {
      // if (this.muitFlag) {
      //   erpOmcContractManagerFinalIds({ ids: value }).then((res) => {
      //     if (res.success) {
      //       const contractName = res.result.map(i => i.htmc).join(',')
      //       this.$refs.hSelectInputPopup.title = contractName
      //       this.$emit('update:contact-name', contractName)
      //       this.$emit('select', {
      //         data: res.result,
      //         id: value,
      //       })
      //     }
      //   })
      // } else {
      erpFinanceReimbursementBillQueryById({ id: value }).then((res) => {
        if (res.success) {
          this.$refs.hSelectInputPopup.title = res.result.billNo
          this.$emit('select', {
            data: res.result,
            id: value,
          })
        }
      })
      // }
    },
  },
}
</script>

<style lang="scss" scoped>
// 按钮
.btn {
  position: fixed;
  bottom: 20rpx;
  width: 95%;
}
</style>
